// Converted from UnityScript to C# at http://www.M2H.nl/files/js_to_c.php - by Mike Hergaarden
// Do test the code! You usually need to change a few small bits.

using UnityEngine;
using System.Collections;

class InstantiateBlocks : MonoBehaviour
{
	public Tower towerConnect;
	Transform logicPrefab;
	Transform passionPrefab;
	Transform ethicsPrefab;
	Transform deceptionPrefab;
	public static int SIZE_MULT = 1000;
	public void Awake ()
	{
		
	}


	public void MakeBlock ( int type, int height)
	{
		if (type == 0) {
			GameObject logicBlockClone = Instantiate (logicPrefab, transform.position, transform.rotation) as GameObject;
			Block b = logicBlockClone.gameObject.GetComponent<Block> ();
			b.setHeight (height);
			Transform cloneTrans = logicBlockClone.transform;
			float x = cloneTrans.localScale.x;
			float y = SIZE_MULT * height;
			float z = cloneTrans.localScale.z;
			cloneTrans.localScale = new Vector3 (x, y, z);
			towerConnect.addBlock (b);
		}
		
		if (type == 2) {
			GameObject passionBlockClone = Instantiate (passionPrefab, transform.position, transform.rotation) as GameObject;
			Block b = passionBlockClone.gameObject.GetComponent<Block> ();
			b.setHeight (height);
			Transform cloneTrans = passionBlockClone.transform;
			float x = cloneTrans.localScale.x;
			float y = SIZE_MULT * height;
			float z = cloneTrans.localScale.z;
			cloneTrans.localScale = new Vector3 (x, y, z);
			towerConnect.addBlock (b);
		}
		
		if (type == 1) {
			GameObject ethicsBlockClone = Instantiate (ethicsPrefab, transform.position, transform.rotation) as GameObject;
			Block b = ethicsBlockClone.gameObject.GetComponent<Block> ();
			b.setHeight (height);
			Transform cloneTrans = ethicsBlockClone.transform;
			float x = cloneTrans.localScale.x;
			float y = SIZE_MULT * height;
			float z = cloneTrans.localScale.z;
			cloneTrans.localScale = new Vector3 (x, y, z);
			towerConnect.addBlock (b);
		}
		
		if (type == 3) {
			GameObject deceptionBlockClone = Instantiate (deceptionPrefab, transform.position, transform.rotation) as GameObject;
			Block b = deceptionBlockClone.gameObject.GetComponent<Block> ();
			b.setHeight (height);
			Transform cloneTrans = deceptionBlockClone.transform;
			float x = cloneTrans.localScale.x;
			float y = SIZE_MULT * height;
			float z = cloneTrans.localScale.z;
			cloneTrans.localScale = new Vector3 (x, y, z);
			towerConnect.addBlock (b);
		}
		
		
		
	}


	public void MakeBlockAtIndex ( int type, int height, int index)
	{
		if (type == 0) {
			GameObject logicBlockClone = Instantiate (logicPrefab, transform.position, transform.rotation) as GameObject;
			Block b = logicBlockClone.gameObject.GetComponent<Block> ();
			b.setHeight (height);
			Transform cloneTrans = logicBlockClone.transform;
			float x = cloneTrans.localScale.x;
			float y = SIZE_MULT * height;
			float z = cloneTrans.localScale.z;
			cloneTrans.localScale = new Vector3 (x, y, z);
			towerConnect.addBlockAt (index, b);
		}
		
		if (type == 2) {
			GameObject passionBlockClone = Instantiate (passionPrefab, transform.position, transform.rotation) as GameObject;
			Block b = passionBlockClone.gameObject.GetComponent<Block> ();
			b.setHeight (height);
			Transform cloneTrans = passionBlockClone.transform;
			float x = cloneTrans.localScale.x;
			float y = SIZE_MULT * height;
			float z = cloneTrans.localScale.z;
			cloneTrans.localScale = new Vector3 (x, y, z);
			towerConnect.addBlockAt (index, b);
		}
		
		if (type == 1) {
			GameObject ethicsBlockClone = Instantiate (ethicsPrefab, transform.position, transform.rotation) as GameObject;
			Block b = ethicsBlockClone.gameObject.GetComponent<Block> ();
			b.setHeight (height);
			Transform cloneTrans = ethicsBlockClone.transform;
			float x = cloneTrans.localScale.x;
			float y = SIZE_MULT * height;
			float z = cloneTrans.localScale.z;
			cloneTrans.localScale = new Vector3 (x, y, z);
			towerConnect.addBlockAt (index, b);
		}
		
		if (type == 3) {
			GameObject deceptionBlockClone = Instantiate (deceptionPrefab, transform.position, transform.rotation) as GameObject;
			Block b = deceptionBlockClone.gameObject.GetComponent<Block> ();
			b.setHeight (height);
			Transform cloneTrans = deceptionBlockClone.transform;
			float x = cloneTrans.localScale.x;
			float y = SIZE_MULT * height;
			float z = cloneTrans.localScale.z;
			cloneTrans.localScale = new Vector3 (x, y, z);
			towerConnect.addBlockAt (index, b);
		}
		
		
		
	}
	
	
//	void makeInitialBlocks(string type ,Tower towerConnect  ){
//		if(type == "Logic")
//		{
//			//Debug.Log("Making a Logic Block");
//			GameObject logicBlockClone=Instantiate(logicPrefab,transform.position,transform.rotation) as GameObject;
//			Block curTower=logicBlockClone.GetComponent<Block>();
//			int curBlockSize= curTower.getHeight();
//			curTower.setHeight( (curBlockSize/2) + int.Parse((curBlockSize/2)*(startingSizeBuff/100.0f)));
//			towerConnect.addBlock(curTower);
//		}
//		
//		else if(type == "Deception")
//		{
//			GameObject deceptionBlockClone=Instantiate(deceptionPrefab,transform.position,transform.rotation) as GameObject;
//			curTower=deceptionBlockClone.GetComponent<Block>();
//			curBlockSize= curTower.getHeight();
//			curTower.setHeight( (curBlockSize/2) + int.Parse((curBlockSize/2)*(startingSizeBuff/100.0f)));
//			towerConnect.addBlock(curTower);
//		}
//		
//		else if(type == "Ethics")
//		{
//			GameObject ethicsBlockClone=Instantiate(ethicsPrefab,transform.position,transform.rotation) as GameObject;
//			curTower=ethicsBlockClone.GetComponent<Block>();
//			curBlockSize= curTower.getHeight();
//			curTower.setHeight( (curBlockSize/2) + int.Parse((curBlockSize/2)*(startingSizeBuff/100.0f)));
//			towerConnect.addBlock(curTower);
//		}
//		
//		else if(type == "Passion")
//		{
//			GameObject passionBlockClone=Instantiate(passionPrefab,transform.position,transform.rotation) as GameObject;
//			curTower=passionBlockClone.GetComponent<Block>();
//			curBlockSize= curTower.getHeight();
//			curTower.setHeight( (curBlockSize/2) + int.Parse((curBlockSize/2)*(startingSizeBuff/100.0f)));
//			towerConnect.addBlock(curTower);
//		}
//		
//		
//	}
}
